expo2.ipynb
No Headings
The table of contents shows headings in notebooks and supported files.
- File
- Edit
- View
- Run
- Kernel
- Settings
- Help
Kernel status: Idle
[154]:
#Importo la base de datos del banco nacion
import wbdata
import pandas as pd
import os
#Importo matplotlib.pyplot
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from ISLP import load_data
import statsmodels.api as sm
from sklearn.preprocessing import scale
from sklearn.linear_model import Lasso, LassoCV, Ridge, RidgeCV, ElasticNet, ElasticNetCV
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error
[162]:
Selection deleted
wbdata.get_countries(query='e')
[162]:
id name ---- -------------------------------------------------------------------------------- AFE Africa Eastern and Southern AFW Africa Western and Central ARE United Arab Emirates ARG Argentina ARM Armenia ASM American Samoa AZE Azerbaijan BEA East Asia & Pacific (IBRD-only countries) BEC Europe & Central Asia (IBRD-only countries) BEL Belgium BEN Benin BGD Bangladesh BHI IBRD countries classified as high income BHS Bahamas, The BIH Bosnia and Herzegovina BLA Latin America & the Caribbean (IBRD-only countries) BLR Belarus BLZ Belize BMN Middle East & North Africa (IBRD-only countries) BMU Bermuda BRN Brunei Darussalam BSS Sub-Saharan Africa (IBRD-only countries) CAF Central African Republic CEA East Asia and the Pacific (IFC classification) CEB Central Europe and the Baltics CEU Europe and Central Asia (IFC classification) CHE Switzerland CHI Channel Islands CHL Chile CIV Cote d'Ivoire CLA Latin America and the Caribbean (IFC classification) CME Middle East and North Africa (IFC classification) CMR Cameroon COD Congo, Dem. Rep. COG Congo, Rep. CPV Cabo Verde CSS Caribbean small states CZE Czechia DEA East Asia & Pacific (IDA-eligible countries) DEC Europe & Central Asia (IDA-eligible countries) DEU Germany DLA Latin America & the Caribbean (IDA-eligible countries) DMN Middle East & North Africa (IDA-eligible countries) DNK Denmark DNS IDA countries in Sub-Saharan Africa not classified as fragile situations DOM Dominican Republic DSA South Asia (IDA-eligible countries) DSF IDA countries in Sub-Saharan Africa classified as fragile situations DSS Sub-Saharan Africa (IDA-eligible countries) DZA Algeria EAP East Asia & Pacific (excluding high income) EAR Early-demographic dividend EAS East Asia & Pacific ECA Europe & Central Asia (excluding high income) ECS Europe & Central Asia ECU Ecuador EGY Egypt, Arab Rep. EMU Euro area ERI Eritrea EST Estonia ETH Ethiopia EUU European Union FCS Fragile and conflict affected situations FRA France FRO Faroe Islands FSM Micronesia, Fed. Sts. FXS IDA countries classified as fragile situations, excluding Sub-Saharan Africa GBR United Kingdom GEO Georgia GIN Guinea GMB Gambia, The GNB Guinea-Bissau GNQ Equatorial Guinea GRC Greece GRD Grenada GRL Greenland GTM Guatemala HIC High income HPC Heavily indebted poor countries (HIPC) IBB IBRD, including blend IDB IDA blend IDN Indonesia IMN Isle of Man INX Not classified IRL Ireland IRN Iran, Islamic Rep. ISL Iceland ISR Israel KEN Kenya KGZ Kyrgyz Republic KNA St. Kitts and Nevis KOR Korea, Rep. LAC Latin America & Caribbean (excluding high income) LBN Lebanon LBR Liberia LCN Latin America & Caribbean LDC Least developed countries: UN classification LIC Low income LIE Liechtenstein LMC Lower middle income LMY Low & middle income LSO Lesotho LTE Late-demographic dividend LUX Luxembourg MAF St. Martin (French part) MDE Middle East (developing only) MDV Maldives MEA Middle East & North Africa MEX Mexico MIC Middle income MKD North Macedonia MNA Middle East & North Africa (excluding high income) MNE Montenegro MNP Northern Mariana Islands MOZ Mozambique NAC North America NCL New Caledonia NER Niger NGA Nigeria NLD Netherlands NPL Nepal NRS Non-resource rich Sub-Saharan Africa countries NXS IDA countries not classified as fragile situations, excluding Sub-Saharan Africa NZL New Zealand OED OECD members OSS Other small states PER Peru PHL Philippines PNG Papua New Guinea PRE Pre-demographic dividend PRI Puerto Rico PRK Korea, Dem. People's Rep. PSE West Bank and Gaza PSS Pacific island small states PST Post-demographic dividend PYF French Polynesia RRS Resource rich Sub-Saharan Africa countries RUS Russian Federation SEN Senegal SGP Singapore SLE Sierra Leone SLV El Salvador SRB Serbia SSA Sub-Saharan Africa (excluding high income) SST Small states STP Sao Tome and Principe SUR Suriname SVK Slovak Republic SVN Slovenia SWE Sweden SWZ Eswatini SXM Sint Maarten (Dutch part) SXZ Sub-Saharan Africa excluding South Africa SYC Seychelles SYR Syrian Arab Republic TEA East Asia & Pacific (IDA & IBRD countries) TEC Europe & Central Asia (IDA & IBRD countries) TKM Turkmenistan TLA Latin America & the Caribbean (IDA & IBRD countries) TLS Timor-Leste TMN Middle East & North Africa (IDA & IBRD countries) TSS Sub-Saharan Africa (IDA & IBRD countries) TUR Turkiye UKR Ukraine UMC Upper middle income USA United States UZB Uzbekistan VCT St. Vincent and the Grenadines VEN Venezuela, RB VNM Viet Nam XZN Sub-Saharan Africa excluding South Africa and Nigeria YEM Yemen, Rep. ZWE Zimbabwe
[166]:
Selection deleted
indicadores = {"HD.HCI.OVRL":"indice_capital_humano","SP.DYN.LE00.IN":"Esperanza_de_vida", "NY.GNP.PCAP.CD":"Ingreso_Percapita", "SE.SEC.ENRR":"Cumplimiento_Educacion_Secundaria", "HD.HCI.AMRT":"Supervivencia_15-60", "HD.HCI.MORT":"Probabilidad de sobrevivir a los 5"}
df = wbdata.get_dataframe(indicadores, country=['ESP','GBR','FRA','BEL','NLD','DEU',"DNK","IRL","ISL",'MAR','NGA','DZA','COD','SEN','CMR',"KEN","GHA","EGY"])
df = df.reset_index()
df = df.dropna()
df = df.sort_values(by='date')
df
[166]:
| country | date | indice_capital_humano | Esperanza_de_vida | Ingreso_Percapita | Cumplimiento_Educacion_Secundaria | Supervivencia_15-60 | Probabilidad de sobrevivir a los 5 | |
|---|---|---|---|---|---|---|---|---|
| 50 | Algeria | 2010 | 0.531283 | 74.144000 | 4870.0 | 100.709122 | 0.895640 | 0.972591 |
| 895 | Netherlands | 2010 | 0.797099 | 80.702439 | 53470.0 | 124.569527 | 0.936495 | 0.995537 |
| 830 | Morocco | 2010 | 0.474435 | 70.821000 | 3190.0 | 63.267460 | 0.916093 | 0.967947 |
| 1025 | Senegal | 2010 | 0.389767 | 64.221000 | 1340.0 | 36.972530 | 0.790471 | 0.933612 |
| 700 | Ireland | 2010 | 0.766303 | 80.743902 | 44980.0 | 118.096909 | 0.929608 | 0.995826 |
| 635 | Iceland | 2010 | 0.755178 | 81.897561 | 38020.0 | 108.819038 | 0.945691 | 0.997383 |
| 1090 | Spain | 2010 | 0.708286 | 81.626829 | 31930.0 | 122.622513 | 0.935105 | 0.996145 |
| 440 | France | 2010 | 0.756892 | 81.663415 | 43960.0 | 106.424942 | 0.917406 | 0.995725 |
| 375 | Egypt, Arab Rep. | 2010 | 0.478853 | 69.078000 | 2200.0 | 65.257210 | 0.838623 | 0.971035 |
| 505 | Germany | 2010 | 0.760740 | 79.987805 | 44650.0 | 104.891357 | 0.923014 | 0.995822 |
| 115 | Belgium | 2010 | 0.752727 | 80.182927 | 47110.0 | 160.660477 | 0.919607 | 0.995539 |
| 1155 | United Kingdom | 2010 | 0.765454 | 80.402439 | 41760.0 | 103.461151 | 0.926647 | 0.994842 |
| 310 | Denmark | 2010 | 0.748738 | 79.100000 | 61290.0 | 118.944054 | 0.919474 | 0.995894 |
| 180 | Cameroon | 2010 | 0.379783 | 56.965000 | 1450.0 | 44.039508 | 0.649568 | 0.892831 |
| 317 | Denmark | 2017 | 0.774000 | 81.102439 | 56600.0 | 130.324432 | 0.931300 | 0.995700 |
| 1162 | United Kingdom | 2017 | 0.781000 | 81.256098 | 41660.0 | 125.731430 | 0.936300 | 0.995700 |
| 577 | Ghana | 2017 | 0.439000 | 63.829000 | 1830.0 | 66.381920 | 0.763000 | 0.950700 |
| 187 | Cameroon | 2017 | 0.394000 | 60.817000 | 1410.0 | 50.637009 | 0.670900 | 0.916000 |
| 707 | Ireland | 2017 | 0.806000 | 82.156098 | 53660.0 | 125.307121 | 0.945600 | 0.996500 |
| 512 | Germany | 2017 | 0.795000 | 80.992683 | 43780.0 | 101.095642 | 0.931300 | 0.996300 |
| 642 | Iceland | 2017 | 0.740000 | 82.660976 | 62450.0 | 115.741142 | 0.952400 | 0.997900 |
| 447 | France | 2017 | 0.765000 | 82.575610 | 38300.0 | 103.756081 | 0.925600 | 0.995800 |
| 122 | Belgium | 2017 | 0.757000 | 81.492683 | 42480.0 | 158.670288 | 0.929100 | 0.996200 |
| 837 | Morocco | 2017 | 0.500000 | 73.608000 | 3160.0 | 78.536102 | 0.931600 | 0.976700 |
| 382 | Egypt, Arab Rep. | 2017 | 0.486000 | 70.709000 | 2880.0 | 79.361198 | 0.853300 | 0.977900 |
| 902 | Netherlands | 2017 | 0.800000 | 81.760976 | 46200.0 | 115.225227 | 0.944400 | 0.996100 |
| 1097 | Spain | 2017 | 0.743000 | 83.282927 | 27120.0 | 120.555923 | 0.944500 | 0.996900 |
| 708 | Ireland | 2018 | 0.813675 | 82.204878 | 59520.0 | 154.908295 | 0.939922 | 0.996267 |
| 838 | Morocco | 2018 | 0.492541 | 73.946000 | 3380.0 | 79.016258 | 0.931606 | 0.976617 |
| 123 | Belgium | 2018 | 0.762760 | 81.595122 | 45980.0 | 156.509766 | 0.929123 | 0.996235 |
| 578 | Ghana | 2018 | 0.443490 | 64.138000 | 2060.0 | 67.753822 | 0.762185 | 0.950025 |
| 1163 | United Kingdom | 2018 | 0.776982 | 81.256098 | 42020.0 | 120.190453 | 0.931713 | 0.995667 |
| 513 | Germany | 2018 | 0.763773 | 80.892683 | 47540.0 | 100.837303 | 0.928101 | 0.996260 |
| 903 | Netherlands | 2018 | 0.803039 | 81.812195 | 50480.0 | 114.500320 | 0.944422 | 0.996070 |
| 448 | France | 2018 | 0.755960 | 82.675610 | 41130.0 | 103.773331 | 0.924162 | 0.995921 |
| 188 | Cameroon | 2018 | 0.393321 | 61.189000 | 1520.0 | 46.472948 | 0.696741 | 0.921008 |
| 1098 | Spain | 2018 | 0.736156 | 83.431707 | 29340.0 | 119.430199 | 0.944505 | 0.996882 |
| 383 | Egypt, Arab Rep. | 2018 | 0.492512 | 70.974000 | 2710.0 | 79.986839 | 0.853568 | 0.978053 |
| 318 | Denmark | 2018 | 0.770832 | 80.953659 | 61090.0 | 129.849564 | 0.929605 | 0.995741 |
| 643 | Iceland | 2018 | 0.743431 | 82.860976 | 72600.0 | 114.649406 | 0.952734 | 0.997972 |
| 968 | Nigeria | 2018 | 0.354753 | 52.669000 | 1950.0 | 42.168449 | 0.651890 | 0.877904 |
| 1035 | Senegal | 2020 | 0.420111 | 67.496000 | 1440.0 | 46.348549 | 0.825251 | 0.956372 |
| 970 | Nigeria | 2020 | 0.360610 | 53.072000 | 2060.0 | 45.889950 | 0.658540 | 0.880086 |
| 1100 | Spain | 2020 | 0.728255 | 82.231707 | 27180.0 | 117.367767 | 0.946016 | 0.996966 |
| 580 | Ghana | 2020 | 0.450056 | 64.309000 | 2250.0 | 73.274048 | 0.768254 | 0.952092 |
| 840 | Morocco | 2020 | 0.504116 | 73.133000 | 3260.0 | 81.396782 | 0.934124 | 0.977589 |
| 710 | Ireland | 2020 | 0.792599 | 82.456098 | 66310.0 | 135.224670 | 0.944305 | 0.996343 |
| 645 | Iceland | 2020 | 0.745282 | 83.063415 | 65820.0 | 110.487320 | 0.954819 | 0.998038 |
| 515 | Germany | 2020 | 0.751162 | 81.041463 | 48020.0 | 101.307800 | 0.930892 | 0.996340 |
| 450 | France | 2020 | 0.762737 | 82.175610 | 39200.0 | 104.566566 | 0.926031 | 0.995956 |
| 385 | Egypt, Arab Rep. | 2020 | 0.494375 | 69.790000 | 2960.0 | 83.162628 | 0.856794 | 0.978775 |
| 320 | Denmark | 2020 | 0.755095 | 81.602439 | 62710.0 | 129.995193 | 0.931701 | 0.995777 |
| 190 | Cameroon | 2020 | 0.397402 | 61.674000 | 1540.0 | 45.259029 | 0.704236 | 0.923940 |
| 125 | Belgium | 2020 | 0.760420 | 80.695122 | 46090.0 | 151.727509 | 0.931235 | 0.996348 |
| 905 | Netherlands | 2020 | 0.789915 | 81.358537 | 50030.0 | 136.284164 | 0.946277 | 0.996126 |
| 1165 | United Kingdom | 2020 | 0.782943 | 80.331756 | 38770.0 | 114.651649 | 0.933412 | 0.995742 |
[200]:
| count | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|
| Esperanza_de_vida | 25.0 | 1.030287e-15 | 1.020621 | -2.619058 | -0.290509 | 0.530714 | 0.605304 | 0.801949 |
| Ingreso_Percapita | 25.0 | 3.552714e-17 | 1.020621 | -1.431371 | -1.334923 | 0.567481 | 0.793971 | 1.203061 |
| Cumplimiento_Educacion_Secundaria | 25.0 | 3.996803e-16 | 1.020621 | -1.699291 | -0.593887 | 0.173205 | 0.672207 | 1.841811 |
| Supervivencia_15-60 | 25.0 | 7.904788e-16 | 1.020621 | -2.406163 | 0.333213 | 0.442597 | 0.479543 | 0.628496 |
| Probabilidad de sobrevivir a los 5 | 25.0 | 1.176836e-16 | 1.020621 | -2.831670 | -0.004022 | 0.545472 | 0.556930 | 0.578859 |
Coeficiente de determinación: 0.9642260983852513 Intercepto: 0.22673553927021511 Coeficientes: [ 1.81261704e-02 1.94590172e-06 6.61194071e-04 -4.85421320e-01 -6.64697653e-01]
Respuesta predicha: [0.56550497 0.75964777 0.47040559 0.41358855 0.74275063 0.73514169 0.73347204 0.75570526 0.47375359 0.72287512 0.76991453 0.7227092 0.75012439 0.3824561 0.77920762 0.74745712 0.42885868 0.43080724 0.78179477 0.73254698 0.79749434 0.75543416 0.77828281 0.51761465 0.50227843 0.75429859 0.74770225 0.81656543 0.52453904 0.78548721 0.43665829 0.7467424 0.73945995 0.76308554 0.76338275 0.41913856 0.75398408 0.50693309 0.78572992 0.81993848 0.31311644 0.44733437 0.31841762 0.72587686 0.43945783 0.50927483 0.81913888 0.80660665 0.74199362 0.75015829 0.48601235 0.79969712 0.42157861 0.7651251 0.76745225 0.7191269 ]
[207]:
# Especificamos el modelo
model = sm.OLS(y, x)
# Ajustamos el modelo
results = model.fit()
print(results.summary())
OLS Regression Results
==========================================================================================
Dep. Variable: indice_capital_humano R-squared (uncentered): 0.998
Model: OLS Adj. R-squared (uncentered): 0.998
Method: Least Squares F-statistic: 5053.
Date: Sat, 17 May 2025 Prob (F-statistic): 1.88e-67
Time: 19:19:06 Log-Likelihood: 116.79
No. Observations: 56 AIC: -223.6
Df Residuals: 51 BIC: -213.4
Df Model: 5
Covariance Type: nonrobust
======================================================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------------------------------
Esperanza_de_vida 0.0174 0.003 6.831 0.000 0.012 0.022
Ingreso_Percapita 1.999e-06 3.88e-07 5.151 0.000 1.22e-06 2.78e-06
Cumplimiento_Educacion_Secundaria 0.0006 0.000 2.302 0.025 8.17e-05 0.001
Supervivencia_15-60 -0.5274 0.180 -2.932 0.005 -0.889 -0.166
Probabilidad de sobrevivir a los 5 -0.3354 0.093 -3.619 0.001 -0.522 -0.149
==============================================================================
Omnibus: 0.013 Durbin-Watson: 2.115
Prob(Omnibus): 0.994 Jarque-Bera (JB): 0.080
Skew: -0.025 Prob(JB): 0.961
Kurtosis: 2.822 Cond. No. 1.68e+06
==============================================================================
Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[3] The condition number is large, 1.68e+06. This might indicate that there are
strong multicollinearity or other numerical problems.
Notebook cell shifted up successfully
Common Tools
No metadata.
Advanced Tools
No metadata.
Anaconda Assistant
AI-powered coding, insights and debugging in your notebooks.
To enable the following extensions, create an account or sign in.
- Anaconda Assistant4.1.0
- Coming soon!
- Data Catalogs
- Panel Deployments
- Sharing
Already have an account? Sign In
For more information, read our Anaconda Assistant documentation.
![Python [conda env:base] *](./expo2_files/logo-64x64.png)